package org.jeecg.modules.demo.dtwlwjc.service.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.dtwlwjc.entity.ZwglAlarmSetting;
import org.jeecg.modules.demo.dtwlwjc.mapper.ZwglAlarmSettingMapper;
import org.jeecg.modules.demo.dtwlwjc.service.IZwglAlarmSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: 报警设置
 * @Author: jeecg-boot
 * @Date:   2023-04-17
 * @Version: V1.0
 */
@Service
public class ZwglAlarmSettingServiceImpl extends ServiceImpl<ZwglAlarmSettingMapper, ZwglAlarmSetting> implements IZwglAlarmSettingService {


    @Autowired
    private ZwglAlarmSettingMapper zwglAlarmSettingMapper;

    @Override
    @Transactional
    public Result<?> openDataStatus(String id, String pflag) {
        ZwglAlarmSetting zwglAlarmSetting = zwglAlarmSettingMapper.selectById(id);
        if (oConvertUtils.isEmpty(zwglAlarmSetting) || oConvertUtils.isEmpty(zwglAlarmSetting.getId())) {
            return Result.error("数据异常，稍后重试");
        }
        zwglAlarmSetting.setIsOpen(pflag);
        if (zwglAlarmSettingMapper.updateById(zwglAlarmSetting) <= 0) {
            throw new JeecgBootException("数据更新异常");
        }
        return Result.OK();
    }
}
